package servlet.refresh;

import java.io.IOException;
import java.net.URLDecoder;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Create By IntelliJ IDEA
 *
 * @Author: jsonor
 * @Create-Time: 2017/9/28 11:25
 * @Description: 页面刷新
 */
@WebServlet(name = "refreshServlet", value = {"/refresh"})
public class RefreshServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req,
      HttpServletResponse resp)
      throws ServletException, IOException {

    String name = req.getParameter("userName");
    resp.addHeader("content-type", "text/html; charset=UTF-8");
    if (!name.equals("123")) {
      resp.addHeader("refresh", "3;url=/location");
      resp.getWriter().println("3秒钟以后跳转回主页");
    } else {
      resp.getWriter().println("登录成功");
    }

  }
}
